<?php
/**
 * Eren Framework
 * 
 * Default Session Operate Class
 * 
 * @category System
 * @author Manu Soros Leu
 * @copyright manusoros@gmail.com
 */

class Eren_Session_Default extends Eren_Session_Abstract
{   
    public function __construct()
    {
        $this->_init();
    }
    
    /**
     * Init Session
     */
    private function _init()
    {
        if(!isset($_SESSION)){
            session_start();
        }
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::getSessionID()
     */
    public function getSessionID()
    {
        $this->_init();
        return session_id();
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::set()
     */
    public function set($key, $value)
    {
        $this->_init();
        $_SESSION[$key] = $value;
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::get()
     */
    public function get($key, $default = NULL)
    {
        $this->_init();
        if(isset($_SESSION[$key])){
            return $_SESSION[$key];
        }
        return $default;
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::getAll()
     */
    public function getAll()
    {
        $this->_init();
        return $_SESSION;
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::delete()
     */
    public function delete($key)
    {
        $this->_init();
        if(isset($_SESSION[$key])){
            unset($_SESSION[$key]);
        }
    }
    
    /**
     * (non-PHPdoc)
     * @see Eren_Session_Abstract::delAll()
     */
    public function delAll()
    {
        $this->_init();
        $all = $this->getAll();
        foreach ($all as $key=>$value){
            $this->delete($key);
        }
    }
}